package com.tangyee.home_exercise_diet.dao;

import android.database.Cursor;
import android.database.CursorWrapper;
import android.util.Log;

import com.tangyee.home_exercise_diet.beans.FoodOrExercise;
import com.tangyee.home_exercise_diet.beans.TypeEnum;

import static com.tangyee.home_exercise_diet.dao.FoodOrExerciseDbSchema.*;

public class FoodOrExerciseDbCursorWrapper extends CursorWrapper {
    /**
     * Creates a cursor wrapper.
     *
     * @param cursor The underlying cursor to wrap.
     */
    public FoodOrExerciseDbCursorWrapper(Cursor cursor) {
        super(cursor);
    }

    /**
     * 获得一条记录
     * @return
     */
    public FoodOrExercise getFoodOrExerciseRecord() {

        String data = getString(getColumnIndex(FoodOrExerciseTable.Cloumns.DATE));
        String type = getString(getColumnIndex(FoodOrExerciseTable.Cloumns.TYPE));
        String name = getString(getColumnIndex(FoodOrExerciseTable.Cloumns.NAME));
        int perUnitCalorie = getInt(getColumnIndex(FoodOrExerciseTable.Cloumns.PER_UNIT_CALORIE));
        String unit = getString(getColumnIndex(FoodOrExerciseTable.Cloumns.UNIT));
        double amount = getDouble(getColumnIndex(FoodOrExerciseTable.Cloumns.AMOUNT));
        int img = getInt(getColumnIndex(FoodOrExerciseTable.Cloumns.IMAGE));

        FoodOrExercise foodOrExercise = null;
        try {
            foodOrExercise = new FoodOrExercise(data, TypeEnum.valueOf(type), name, perUnitCalorie, unit, amount, img);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return foodOrExercise;

    }

    /**
     * 获得记录总数
     * @return
     */
    public int getRecordsCount() {
        return getCount();
    }
}

